<script setup>
import { defineProps, defineEmits } from 'vue'
import { generateRandomString, randomTime } from '@/utils/mockData'

const props = defineProps({
  data: {
    type: Array,
    required: true,
    default: () => []
  }
})

const emit = defineEmits(['view-log', 'download-log'])

const handleViewLog = (taskId) => {
  emit('view-log', taskId)
}

const handleDownloadLog = (taskId) => {
  emit('download-log', taskId)
}
</script>

<template>
  <div class="subtask-table">
    <table>
      <thead>
        <tr>
          <th>子任务编号</th>
          <th>父任务编号</th>
          <th>运行系统</th>
          <th>排队时间</th>
          <th>开始时间</th>
          <th>结束时间</th>
          <th>CPU占用</th>
          <th>内存占用(GB)</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="task in data" :key="task.subtaskId">
          <td>{{ task.subtaskId }}</td>
          <td>{{ task.parentTaskId }}</td>
          <td>{{ task.os }}</td>
          <td>{{ task.queueTime }}</td>
          <td>{{ task.startTime }}</td>
          <td>{{ task.endTime }}</td>
          <td>{{ task.cpu }}</td>
          <td>{{ task.memory }}</td>
          <td>
            <button 
              class="log-view-btn"
              @click="handleViewLog(task.subtaskId)"
            >
              日志查看
            </button>
            <button
              class="log-download-btn"
              @click="handleDownloadLog(task.subtaskId)"
            >
              日志下载
            </button>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<style scoped>
.subtask-table {
  border: 1px solid #ebeef5;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid #ebeef5;
}

th {
  background-color: #f5f7fa;
  font-weight: 600;
  color: #606266;
}

button {
  padding: 6px 12px;
  border-radius: 3px;
  cursor: pointer;
  margin-right: 8px;
  font-size: 12px;
  transition: all 0.3s;
}

.log-view-btn {
  background-color: #409eff;
  color: white;
  border: 1px solid #409eff;
}

.log-view-btn:hover {
  background-color: #66b1ff;
}

.log-download-btn {
  background-color: #67c23a;
  color: white;
  border: 1px solid #67c23a;
}

.log-download-btn:hover {
  background-color: #85ce61;
}
</style>
